#include<bits/stdc++.h>
using namespace std;
int T , n , a[100005] , dp[105][105][105];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    freopen("color.in" , "r" , stdin);
    freopen("color.out" , "w" , stdout);
    cin >> T;
    while(T--){
        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        memset(dp , 0 , sizeof(dp));
        for(int i = 2; i <= n; i++){
            for(int j = 0; j <i; j++){
                for(int k = 0; k < i; k++){
                    if(k == j) continue;
                    if(a[i] == a[j]){
                        dp[i][i][k] = max(dp[i][i][k] , dp[i - 1][j][k] + a[i]);
                    }else{
                        dp[i][i][k] = max(dp[i][i][k] , dp[i - 1][j][k]);
                    }if(a[i] == a[k]){
                        dp[i][j][i] = max(dp[i][j][i] , dp[i - 1][j][k] + a[i]);
                    }else{
                        dp[i][j][i] = max(dp[i][j][i] , dp[i - 1][j][k]);
                    }
                }
            }
        }
        int ans = -1;
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                ans = max(ans , dp[n][i][j]);
            }
        }
        cout << ans;
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
